<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
    用户名：<input type="text"><span></span>
    <br>
    <br>
    密&emsp;码：<input type="text"><span></span>
    <br><br>
    <button>用户登录</button>
</body>
<script>
    $('button').click(function(){
        $.ajax({
            url:'yonghu.php',
            method:'GET',
            dataType:'json',
            success:function(res){
                // console.log(res);
                if(res.code==200){
                    if($('input:eq(0)').val()=='张三'){
                        $('span:eq(0)').html('√')
                    }else{
                        $('span:eq(0)').html('用户名输入不正确')
                        $('span:eq(0)').css('color','red')
                    }
                    if($('input:eq(1)').val()==113456){
                        $('span:eq(1)').html('√')
                    }else{
                        $('span:eq(1)').html('密码输入不正确')
                        $('span:eq(1)').css('color','red')
                    }
                    if($('input:eq(0)').val()==''){
                        $('span:eq(0)').html('用户名不能为空')
                        $('span:eq(0)').css('color','red')
                    }
                    if($('input:eq(1)').val()==''){
                        $('span:eq(1)').html('密码不能为空')
                        $('span:eq(1)').css('color','red')
                    }
                    alert(res.msg)
                }else if(res.code==-1){
                    alert(res.msg)
                }
            }

        })
    })
</script>
</html>